﻿using System;
using System.IO;

namespace RazakiSite.UserControls
{
    public partial class UCFileLink : BaseUserControl
    {

        #region >>>Constructor<<<
        
        public UCFileLink()
        {
            //مقدار اولیه دادن به
            //property ها
            LinkEnabled = true;
        }
        
        #endregion

        #region >>>PROPERTY<<<

        public string FilePath
        {
            get;
            set;
        }

        public string LinkName
        {
            get;
            set;
        }

        public bool LinkEnabled
        {
            get;
            set;
        }

        public EIconSize IconSize { get; set; }

        #endregion

        protected void Page_Load(object sender, EventArgs e)
        {
            HypLFile.NavigateUrl = FilePath;
            HypLFile.Text = LinkName;
            HypLFile.Enabled = LinkEnabled;

            FileInfo fileInfo = new FileInfo(MapPath(FilePath));

            switch (IconSize)
            {
                case EIconSize._16:
                    //default 16x16
                    ImgFile.ImageUrl = string.Format("~/Images/MimeTypes/{0}.png", fileInfo.Extension.Remove(0, 1));
                    break;
                case EIconSize._32:
                    ImgFile.ImageUrl = string.Format("~/Images/MimeTypes/{0}-{1}.png", fileInfo.Extension, IconSize);
                    break;
            }

            ImgFile.AlternateText = LinkName;
        }

    }
}